home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 551-575 / disk_559 / apig / apiglib_v11.lzh / e3_drawing.rexx < prev    next >
OS/2 REXX Batch file  |  1991-09-28  |  6KB  |  213 lines

  1.  
  2. /* This example simply opens a window and custom screen
  3.    for drawing                                          */
  4.  
  5.  
  6. /*  add library */
  7.  
  8. x = addlib("apig.library",0,-30,0)
  9. x = addlib("rexxmathlib.library",0,-30,0)
  10.  
  11.  
  12. portname = "example3_port"   /* this is the name of the port that */
  13.                              /* intuimessages will be sent to     */
  14.                              
  15. p = openport(portname)       /* create the port                   */
  16.  
  17. call set_apig_globals()      /* initialize INTUITION constants    */
  18.  
  19. WaitForPort portname         /* this port should be here by now   */
  20.  
  21. wintitle = "This is your Window title"
  22.  
  23. /* the INTUI-Events you want the window to receive                */
  24. winidcmp = CLOSEWINDOW
  25.            
  26. /* set window flags for system gadgets and type of window you want   */
  27. winflags = WINDOWCLOSE+WINDOWDRAG+WINDOWSIZING+WINDOWDEPTH+GIMMEZEROZERO,
  28.            + ACTIVATE
  29.            
  30. /* open a custom screen */           
  31. scr = openscreen(0,0,640,400,3,4,5,LACE+HIRES,CUSTOMSCREEN,scrtitle)
  32.  
  33. /*  open 2 windows, on custom screen, scr NOT = 0  */
  34. win1 = openwindow(portname,0,0,640,199,2,4,winidcmp,winflags,wintitle,scr,0,0,0)
  35. win2 = openwindow(portname,0,201,640,199,2,4,winidcmp,winflags,wintitle,scr,0,0,0)
  36.  
  37. exitme = 0
  38.  
  39. /* draw some stuff */
  40.  
  41. winrasport1 = getwindowrastport(win1) /* to do drawing need windows rastport */
  42. winrasport2 = getwindowrastport(win2)
  43.  
  44. do i = 1 to 20
  45.    x = random(10,639)
  46.    y = random(10,198)
  47.    p = random(1,15)
  48.    
  49.    if i = 1 then 
  50.       call move(winrasport1,x,y)
  51.       
  52.    call setapen(winrasport1,p)
  53.    call draw(winrasport1,x,y)
  54.    
  55.    x = random(10,600)
  56.    y = random(10,180)
  57.    r = random(10,100)
  58.    p = random(1,15)
  59.    call setapen(winrasport2,p)
  60.    call drawcircle(winrasport2,x,y,r)
  61.    
  62. end
  63.  
  64. call clearscreen(winrasport1,0,0)
  65. call clearscreen(winrasport2,0,0)
  66.  
  67. do i = 1 to 10
  68.    x  = random(10,500)
  69.    y  = random(30,160)
  70.    x2 = random(x+10,600)
  71.    y2 = random(y+10,180)
  72.    p  = random(1,15)
  73.    call setapen(winrasport1,p)
  74.    p  = random(1,15)
  75.    call setapen(winrasport2,p)
  76.    call drawellipse(winrasport1,x,y,x+2,y-20)
  77.    call rectfill(winrasport2,x,y,x2,y2)
  78. end
  79.  
  80.  
  81. call clearscreen(winrasport1,0,0)
  82. call clearscreen(winrasport2,0,0)
  83.  
  84. call setapen(winrasport1,9)
  85. call setapen(winrasport2,5)
  86.  
  87. array = allocmem(650*4,MEMF_CLEAR)  /* alloc block of mem. to use as an array */
  88.                                     /* 2 bytes per word, 2 words for X,Y      */
  89. array2 = allocmem(650*4,MEMF_CLEAR)
  90.                             
  91. deltarad = (2 * 3.14159) / 640
  92.  
  93. z = pitext(winrasport1,60,100,"Calculating Array Points ... SIN(X)",1,2,JAM2,0)
  94. z = pitext(winrasport2,60,100,"Calculating Array Points ... COS(X)",1,2,JAM2,0)
  95.  
  96. npoints = 639
  97.  
  98. do i = 0 to npoints
  99.  
  100.    y =   ((1 - sin(i * deltarad)) * 88) 
  101.    
  102.    dx = setx(array,i,i)
  103.    dy = sety(array,i,y) 
  104.    z = pitext(winrasport1,60,125,("  X-Coord = " dx "Y-Coord = " dy "   "),3,4,JAM2,0)
  105.    
  106.    y =   ((1 - cos(i * deltarad)) * 88)
  107.  
  108.    dx = setx(array2,i,i)
  109.    dy = sety(array2,i,y) 
  110.    z = pitext(winrasport2,60,125,("  X-Coord = " dx "Y-Coord = " dy "   "),3,4,JAM2,0)
  111.    
  112.    if i > 500 then 
  113.    do
  114.      z = pitext(winrasport1,90,112,"  SLOW ! aint it," (npoints - i) "points to go.  ",1,2,JAM2,0)
  115.      z = pitext(winrasport2,90,112,"  SLOW ! aint it," (npoints - i) "points to go.  ",1,2,JAM2,0)
  116.    end
  117.    
  118. end
  119.  
  120. call clearscreen(winrasport1,0,0)
  121. call clearscreen(winrasport2,0,0)
  122. z = move(winrasport1,getx(array,0),gety(array,0))
  123. z = move(winrasport2,getx(array2,0),gety(array2,0))
  124. call polydraw(winrasport1,npoints+1,array)
  125. call polydraw(winrasport2,npoints+1,array2)
  126.  
  127. a = freemem(array,(650*4))
  128. a = freemem(array2,(650*4))
  129.  
  130. wait 2 secs
  131.  
  132. linepat = c2d('ffff'x)
  133.  
  134. planemask = 15
  135.  
  136. do i = 10 to 199 by 20
  137.  
  138.    z = setapen(winrasport1,((planemask // 7) + 1))
  139.                                   
  140.    z = setdrpt(winrasport1,linepat)
  141.    z = move(winrasport1,10,i)
  142.    z = draw(winrasport1,640,i)
  143.    
  144.    
  145.    if linepat > 512 then 
  146.       linepat = linepat - 237  /* any number to make linepat different */
  147.       
  148.    if planemask > 10 then
  149.       planemask = planemask - 1   
  150.    else
  151.       planemask = 15
  152.  
  153.    z = setapen(winrasport2,((planemask // 7) + 1))
  154.    z = setdrpt(winrasport2,linepat)
  155.    z = move(winrasport2,10,i)
  156.    z = draw(winrasport2,640,i)
  157.    
  158.    
  159.    if linepat > 1024 then 
  160.       linepat = linepat - 1024
  161.       
  162. end
  163.  
  164. z = pitext(winrasport1,60,120,"DONE... Use the CloseGadget ",3,4,JAM2,0)
  165. z = pitext(winrasport2,60,120,"DONE",5,7,JAM2,0)
  166.  
  167. do forever       /* the main 'wait' loop for message arrival */
  168.  
  169.      x = waitpkt(portname)
  170.   
  171.      do forever  /* get all message packets until getpkt() returns null */
  172.      
  173.         msg = getpkt(portname)
  174.         if msg = '0000 0000'x then leave
  175.         
  176.         class = getarg(msg,0)
  177.         
  178.         select 
  179.               when class = CLOSEWINDOW then
  180.                    do
  181.                        exitme = exitme + 1
  182.                        if getarg(msg,7) = win1 then 
  183.                           do
  184.                              do while msg ~= '0000 0000'x 
  185.                                 call reply(msg,0)
  186.                                 msg = getpkt(portname)
  187.                              end
  188.                              call closewindow(win1)
  189.                           end
  190.                        else   
  191.                        if getarg(msg,7) = win2 then 
  192.                           do
  193.                              do while msg ~= '0000 0000'x 
  194.                                 call reply(msg,0)
  195.                                 msg = getpkt(portname)
  196.                              end
  197.                              call closewindow(win2)
  198.                           end
  199.                    end
  200.               otherwise  call reply(msg,0)
  201.         end
  202.         
  203.      end  
  204.      
  205.    if exitme = 2 then leave
  206.    
  207. end
  208.  
  209. a = closescreen(scr)
  210.  
  211. exit
  212.  
  213.